package pl.edu.pw.perg.compinfodb.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.criterion.Expression;

import pl.edu.pw.perg.compinfodb.entities.VirtualElement;

public class VirtualElementDAO extends GenericSpringDAO<VirtualElement>
		implements IVirtualElementDAO {

	/*
	 * (non-Javadoc)
	 * 
	 * @see pl.edu.pw.perg.compinfodb.dao.IElementDAO#findRoots()
	 */
	public List<VirtualElement> findRoots() {
		return findByCriteria(Expression.isNull("parent"));
	}

	@Override
	public void deleteAll() {
		SQLQuery sqlq = getSession().createSQLQuery("delete from type_fields");
		sqlq.executeUpdate();
		Query q = getSession().createQuery("delete from VirtualElement");
		q.executeUpdate();
	}

}
